package com.jbm.core.common;

import java.util.UUID;

/**
 * Created by root on 16-10-16.
 */
public class ResKey
{
	String key;
	int index;

	public ResKey ( )
	{
		index = -1;
	}

	public ResKey ( String key )
	{
		this ();

		if ( key != null )
		{
			if ( key.length() == 46 )
			{
				this.key = key.substring(0, key.length() - 10);
				index = Integer.parseInt(key.substring(key.length() - 10));
			}else if ( key.substring(0,6).equals("000000"))
			{
				this.key = "";
				index = Integer.parseInt(key);
			}
		}
	}

	public ResKey ( int index )
	{
		this ();

		key = UUID.randomUUID().toString();

		this.index = index;
	}

	public String toString ()
	{
		return this.key+String.format("%010d",this.index);
	}

	public boolean equals ( ResKey reskey )
	{
		return key.equals(reskey.key) && index == reskey.index;
	}
}
